package hikari.persistence.handlersimpl;

import com.gooddies.wiring.annotations.WiringComponent;
import hikari.objects3d.Basic3dObject;
import hikari.objects3d.light.Light3dObject;
import hikari.persistence.file.FileSection;
import hikari.persistence.persisthandlers.IPersistantObject3dReadHandler;
import hikari.persistence.persisthandlers.PersistantHandler;
import java.io.IOException;
import org.swig.jirr.ISceneManager;
import org.swig.jirr.SColorf;
import org.swig.jirr.SLight;

/**
 * @author Dmitry
 */
@WiringComponent(singleton = true, lazy = true)
@PersistantHandler(sectionName = "lightSetting")
public class LightLoadHandler implements IPersistantObject3dReadHandler {

    private LightLoadHandler() {
    }

    @Override
    public Basic3dObject read(ISceneManager sceneManager, Basic3dObject object, FileSection section) throws IOException {
        Light3dObject light = (Light3dObject) object;
        SLight data = light.getLightNode().getLightData();
        float radius = section.readFloat(section.getChunk("rad"));
        light.getLightNode().setRadius(radius);
        float outer = section.readFloat(section.getChunk("outerCone"));
        data.setOuterCone(outer);
        float inner = section.readFloat(section.getChunk("innerCone"));
        data.setInnerCone(inner);
        float falloff = section.readFloat(section.getChunk("falloff"));
        data.setFalloff(falloff);
        data.setAmbientColor(new SColorf(section.readSColor(section.getChunk("amb"))));
        data.setSpecularColor(new SColorf(section.readSColor(section.getChunk("spec"))));
        data.setDiffuseColor(new SColorf(section.readSColor(section.getChunk("diff"))));
        light.getLightNode().setLightData(data);
        return light;
    }
}
